home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / lamstex / inputs / ptmatrix.tex < prev    next >
Text File  |  1991-09-06  |  9KB  |  234 lines

  1. % PTMATRIX.TEX   VERSION 2.0
  2. % COPYRIGHT (C) 1991 BY THE TEXPLORATORS CORPORATION
  3. % ALL RIGHTS RESERVED
  4.  
  5. % THIS FILE SHOULD NOT BE CHANGED IN ANY WAY.
  6.  
  7. \catcode`\@=11
  8. \let\alloc@\alloc@@
  9. \newif\ifformat@
  10. \newcount\ptmrowcount@
  11. \newcount\ptmcolcount@
  12. \newcount\ptmColcount@
  13. \newcount\maxptmrow@
  14. \newbox\ptmbox@
  15. \def\qstrut@{\ifnum\ptmrowcount@<\@ne\Mathstrut@\fi}
  16. \def\GAM@{\global\advance\ptmcolcount@\@ne}
  17. \newif\iflastmrow@
  18. \def\partition\matrix{\global\format@false\bgroup
  19.  \let\endmatrix\ptmendmatrix@
  20.  \null\,\vcenter\bgroup\hbox\bgroup$\global\setbox\ptmbox@\vbox\bgroup
  21.  \Let@\vspace@\normalbaselines\openup\spreadmlines@
  22.  \global\ptmrowcount@\m@ne\global\ptmcolcount@\z@\global\ptmColcount@\z@
  23.  \everycr{\noalign{\iflastmrow@\else\global\advance\ptmrowcount@\@ne
  24.   \ifnum\ptmcolcount@<\ptmColcount@\else\global\ptmColcount@\ptmcolcount@
  25.   \global\maxptmrow@\ptmrowcount@\fi\global\ptmcolcount@\z@\fi}}%
  26.  \tabskip\z@skip\halign\bgroup\hfil\qstrut@$\m@th##$\hfil\GAM@
  27.   &&\quad\hfil$\m@th##$\hfil\GAM@\crcr}
  28. \def\format{\crcr\egroup\iffalse{\fi\ifnum`}=\z@\fi
  29.  \global\advance\ptmrowcount@\m@ne
  30.  \global\format@true\format@}
  31. \def\format@#1\\{\def\preamble@{#1}%
  32.  \def\l{\noexpand\qstrut@$\m@th\the\hashtoks@$\hfil\noexpand\GAM@}%
  33.  \def\c{\noexpand\qstrut@\hfil$\m@th\the\hashtoks@$\hfil\noexpand\GAM@}%
  34.  \def\r{\noexpand\qstrut@\hfil$\m@th\the\hashtoks@$\noexpand\GAM@}%
  35.  \edef\Preamble@{\preamble@}\global\let\Preamble@@\Preamble@
  36.  \ifnum`{=\z@\fi\iffalse}\fi\tabskip\z@skip\halign\bgroup\span\Preamble@\crcr}
  37. \def\formatmatrixgap@{\global\let\matrixgap@\empty
  38.  \setbox4=\vbox{\ialign{\span\Preamble@@\cr\the\toks@\cr}}%
  39.  \setbox4=\vbox{\unvbox4 
  40.   \setboxzl@
  41.   \setboxz@h{\unhbox\z@\count@\z@
  42.    \loop\unskip\setboxzl@\ifvoid\z@\else
  43.    {\let\or\relax\xdef\matrixgap@{\matrixgap@
  44.     \ifnum\count@=\z@\else\or\fi\the\wdz@}}%
  45.    \advance\count@\@ne
  46.    \repeat}%
  47.    {\let\or\relax
  48.    \xdef\matrixgap@##1{\noexpand\ifcase##1 \matrixgap@\noexpand\fi}}%
  49.   }%
  50. }
  51. \newcount\mcolcount@
  52. \newcount\bordercount@
  53. \def\ptmendmatrix@{\crcr\noalign{\global\lastmrow@true}\Mathstrut@\crcr
  54.  \noalign{\global\lastmrow@false\kern-\baselineskip}%
  55.  \egroup\egroup
  56.  \bordercount@\ptmrowcount@\advance\bordercount@\m@ne
  57.  \setbox\z@\vbox   
  58.   {\unvcopy\ptmbox@\unkern\setboxzl@\unskip\setboxzl@
  59.    \count@\ptmrowcount@
  60.    \loop
  61.     \ifnum\count@>\maxptmrow@
  62.     \unskip\setboxzl@\advance\count@\m@ne
  63.    \repeat 
  64.    \global\let\matrixgap@\empty\global\mcolcount@\tw@
  65.    \setbox\tw@\hbox
  66.     {\unhcopy\z@\unskip\setboxzl@\unskip\setboxzl@
  67.      \loop\unskip\setboxzl@
  68.      \ifvoid\z@\else\global\advance\mcolcount@\@ne
  69.      {\let\or\relax\xdef\matrixgap@{\matrixgap@\or10pt}}%
  70.     \repeat}%
  71.    {\let\or\relax\xdef\matrixgap@##1{\noexpand
  72.     \ifcase##1 10pt\matrixgap@\or0pt\noexpand\fi}}%
  73.    \ifformat@
  74.     \toks@{&}\count@\tw@
  75.     \loop
  76.      \ifnum\count@<\mcolcount@\advance\count@\@ne
  77.      \toks@\expandafter{\the\toks@&}%
  78.     \repeat
  79.     \formatmatrixgap@
  80.    \fi
  81.    \xdef\rowbot@{\ifdim\dp\z@>\dp\Mathstrutbox@-\the\dp\z@\else
  82.     -\the\dp\Mathstrutbox@\fi}%
  83.    \xdef\rowtop@{\ifdim\ht\z@>\ht\Mathstrutbox@\the\ht\z@
  84.     \else\the\ht\Mathstrutbox@\fi}%
  85.    \xdef\midrow@{\the\ht\z@}\xdef\midcol@{0pt}%
  86.    \dimen@\z@
  87.    \setbox\tw@\hbox
  88.     {\unhbox\z@ 
  89.      \count@\z@
  90.      \loop
  91.      \unskip\setboxzl@
  92.      \ifvoid\z@\else
  93.      \advance\dimen@\wdz@
  94.      \dimen@ii\matrixgap@\count@
  95.      \advance\dimen@-.5\dimen@ii
  96.      {\let\or\relax\xdef\midcol@{\the\dimen@\or\midcol@}}%
  97.      \advance\dimen@-.5\dimen@ii
  98.      {\let\or\relax\xdef\leftcol@{\the\dimen@\ifnum\count@=\z@\else
  99.       \or\leftcol@\fi}}%
  100.      {\advance\dimen@-\wdz@\advance\dimen@\dimen@ii\let\or\relax
  101.       \xdef\rightcol@{\the\dimen@\ifnum\count@=\z@\else\or\rightcol@\fi}}%
  102.      \advance\dimen@\dimen@ii\advance\count@\@ne
  103.      \repeat
  104.     }%
  105.    \global\let\matrixgap@\relax 
  106.    {\let\or\relax\xdef\midcol@##1{\noexpand
  107.     \ifcase##1 \midcol@\noexpand\else\noexpand\Err@{##1 too large}%
  108.     \noexpand\fi}%
  109.    \xdef\leftcol@##1{\noexpand\ifcase##1 \noexpand\or\leftcol@\noexpand\fi}%
  110.    \xdef\rightcol@##1{\noexpand\ifcase##1 \noexpand\or\rightcol@\noexpand\fi}%
  111.    }%
  112.   }%
  113.   \setbox\z@\vbox
  114.    {\unvcopy\ptmbox@\unkern\setboxzl@\unskip
  115.     \setboxzl@
  116.     \xdef\rowbl@{0pt}%
  117.     \dimen@ii\ht\z@
  118.     \dimen@\midrow@\relax\skip@\lastskip\unskip
  119.     \advance\skip@\lastskip\unskip
  120.     \advance\dimen@.5\skip@\xdef\midrow@{\the\dimen@}%
  121.     \loop
  122.      \setboxzl@
  123.      \ifvoid\z@\else
  124.       \advance\dimen@ii\skip@
  125.       {\let\or\relax\xdef\rowbot@{\rowbot@\or\the\dimen@ii}}%
  126.       \advance\dimen@ii\dp\z@
  127.       {\let\or\relax\xdef\rowbl@{\rowbl@\or\the\dimen@ii}}%
  128.       \advance\dimen@ii\ht\z@
  129.       {\let\or\relax\xdef\rowtop@{\rowtop@\or\the\dimen@ii}}%
  130.       \advance\dimen@.5\skip@
  131.       \advance\dimen@\dp\z@\advance\dimen@\ht\z@
  132.       \skip@\lastskip\unskip\advance\skip@\lastskip\unskip
  133.       \advance\dimen@.5\skip@
  134.       {\let\or\relax\xdef\midrow@{\midrow@\or\the\dimen@}}%
  135.     \repeat
  136.     {\let\or\relax\xdef\midrow@##1{\noexpand
  137.      \ifcase##1 0pt\or\midrow@\noexpand\else
  138.      \noexpand\Err@{##1 too large}\noexpand\fi}%
  139.     \xdef\rowbot@##1{\noexpand\ifcase##1 \or\rowbot@\noexpand\fi}% 
  140.     \xdef\rowbl@##1{\noexpand\ifcase##1 \or\rowbl@\noexpand\fi}%
  141.     \xdef\rowtop@##1{\noexpand\ifcase##1 \or\rowtop@\noexpand\fi}%
  142.     }%
  143.    }%
  144.   \box\ptmbox@
  145.   \let\midcol\midcol@\global\let\midcol@\relax
  146.   \let\midrow\midrow@\global\let\midrow@\relax
  147. }
  148. \def\endpartition{$\egroup\egroup\,\egroup
  149.  \global\let\leftcol@\relax \global\let\rightcol@\relax
  150.  \global\let\rowbot@\relax \global\let\rowtop@\relax
  151.  \global\let\rowbl@\relax}
  152. \newcount\count@@@@@
  153. \edef\countdimen@#1{\setboxz@h{\def\noexpand\next@{\global\dimen@i}%
  154.  \afterassignment\noexpand\next@\global
  155.  \count@@@@@\noexpand\strip@#1 \space0pt}}
  156. \def\hsolid{\ifnum\catcode`\:=\active\expandafter\hsolidA@\else
  157.  \expandafter\hsolidO@\fi}
  158. \def\hsolidO@#1:#2#3{\hsolid@{#1}{#2}{#3}}
  159. \def\hsolid@#1#2#3{\def\HLEADERS{\hsolidleaders}\HPARTITION{#1}{#2}{#3}}
  160. \def\hdashed{\ifnum\catcode`\:=\active\expandafter\hdashedA@\else
  161.  \expandafter\hdashedO@\fi}
  162. \def\hdashedO@#1:#2#3{\hdashed@{#1}{#2}{#3}}
  163. \def\hdashed@#1#2#3{\def\HLEADERS{\hdashedleaders}\HPARTITION{#1}{#2}{#3}}
  164. \def\HPARTITION#1#2#3{\countdimen@{#1}\dimen@\midrow\count@@@@@
  165.  \advance\dimen@\dimen@i\advance\dimen@\dp\Mathstrutbox@
  166.  \smash{\llap{\raise\dimen@
  167.   \hbox{\countdimen@{#2}\dimen@\midcol\count@@@@@\advance\dimen@-\dimen@i
  168.   \countdimen@{#3}\dimen@ii\midcol\count@@@@@\advance\dimen@ii-\dimen@i
  169.   \advance\dimen@-\dimen@ii
  170.   \HLEADERS\hskip\dimen@\hskip\dimen@ii}}}}
  171. \def\vsolid{\ifnum\catcode`\:=\active\expandafter\vsolidA@\else
  172.  \expandafter\vsolidO@\fi}
  173. \def\vsolidO@#1:#2#3{\vsolid@{#1}{#2}{#3}}
  174. \def\vsolid@#1#2#3{\def\VLEADERS{\vsolidleaders}\VPARTITION{#1}{#2}{#3}}
  175. \def\vdashed{\ifnum\catcode`\:=\active\expandafter\vdashedA@\else
  176.  \expandafter\vdashedO@\fi}
  177. \def\vdashedO@#1:#2#3{\vdashed@{#1}{#2}{#3}}
  178. \def\vdashed@#1#2#3{\def\VLEADERS{\vdashedleaders}\VPARTITION{#1}{#2}{#3}}
  179. \newdimen\vextra@
  180. \def\VPARTITION#1#2#3{\countdimen@{#3}\dimen@\midrow\count@@@@@
  181.  \advance\dimen@\dimen@i\advance\dimen@\dp\Mathstrutbox@
  182.  \countdimen@{#2}\dimen@ii\midrow\count@@@@@
  183.  \advance\dimen@ii\dimen@i\advance\dimen@ii\dp\Mathstrutbox@
  184.  \setbox\z@\vbox to\p@{\VLEADERS\vfil}\vextra@\wdz@
  185.  \llap{\hbox{\smash{\vbox to\dimen@{\VLEADERS\vfil\vskip\dimen@ii}}%
  186.   \hskip-\vextra@\relax\countdimen@{#1}\hskip\midcol\count@@@@@
  187.   \hskip-\dimen@i}}}
  188. \def\vleft{\ifnum\catcode`\:=\active\expandafter\vleftA@\else
  189.  \expandafter\vleftO@\fi}
  190. \def\vleftO@#1#2:#3#4{\vleft@#1{#2}{#3}{#4}}
  191. \def\vleft@#1#2#3#4{\dimen@\rowtop@{#4}\advance\dimen@-\rowbot@{#3}%
  192.  \dimen@ii\rowbl@{#3}\advance\dimen@ii.5\dimen@\advance\dimen@ii-\mathaxis@
  193.  \countdimen@{#2}%
  194.  \llap{\hbox{\smash{\raise\dimen@ii\hbox{$\left#1\vcenter{\vbox to
  195.   \dimen@{}}\right.$}}\hskip\leftcol@\count@@@@@\hskip-\dimen@i}}}
  196. \def\vright{\ifnum\catcode`\:=\active\expandafter\vrightA@\else
  197.  \expandafter\vrightO@\fi}
  198. \def\vrightO@#1#2:#3#4{\vright@#1{#2}{#3}{#4}}
  199. \def\vright@#1#2#3#4{\dimen@\rowtop@{#4}\advance\dimen@-\rowbot@{#3}%
  200.  \dimen@ii\rowbl@{#3}\advance\dimen@ii.5\dimen@\advance\dimen@ii-\mathaxis@
  201.  \countdimen@{#2}%
  202.  \llap{\hbox{\smash{\raise\dimen@ii\hbox{\setboxz@h{$\left.\vcenter{\vbox to
  203.   \dimen@{}}\right#1$}\global\dimen\thr@@\wdz@\boxz@}}}%
  204.   \hskip\rightcol@\count@@@@@\hskip-\dimen@i\hskip-\dimen\thr@@}}%
  205. {\catcode`\:=\active
  206.  \gdef\hsolidA@#1:#2#3{\hsolid@{#1}{#2}{#3}}
  207.  \gdef\hdashedA@#1:#2#3{\hdashed@{#1}{#2}{#3}}
  208.  \gdef\vsolidA@#1:#2#3{\vsolid@{#1}{#2}{#3}}
  209.  \gdef\vdashedA@#1:#2#3{\vdashed@{#1}{#2}{#3}}
  210.  \gdef\vleftA@#1#2:#3#4{\vleft@#1{#2}{#3}{#4}}
  211.  \gdef\vrightA@#1#2:#3#4{\vright@#1{#2}{#3}{#4}}
  212. }
  213. \def\bdmatrix#1\\#2\\#3\endbdmatrix{\partition
  214.  \matrix\format\c&\quad\hskip\jot\c&&\quad\c\\
  215.  #1\\\vspace{\jot}\Mathstrut@#2\\#3\endmatrix
  216.  \vleft@(21\bordercount@
  217.  \vright@)\ptmColcount@1\bordercount@\endpartition}
  218. \def\alloc@#1#2#3#4#5{\global\advance\count1#1by\@ne
  219.   \ch@ck#1#4#2%
  220.   \allocationnumber=\count1#1%
  221.   \global#3#5=\allocationnumber
  222.   \wlog{\string#5=\string#2\the\allocationnumber}}
  223. \catcode`\@=\active
  224.  
  225. \def\hsolidleaders{\leaders\hrule}
  226.  
  227. \def\vsolidleaders{\leaders\vrule}
  228.  
  229. \def\hdashedleaders{\xleaders\hbox to5pt{\hfil
  230.   \leaders\hrule\hskip2.5pt\hfil}}
  231.  
  232. \def\vdashedleaders{\xleaders\vbox to5pt{\vfil\leaders\vrule\vskip2.5pt}}
  233.  
  234.